package com.ruoyi.web.controller.production.blade;

import java.util.List;

import com.ruoyi.production.service.blade.IBladeAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.blade.BladePurchase;
import com.ruoyi.production.service.blade.IBladePurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 刀片购买信息Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/baldePurchase")
@Api(value = "刀片购买",tags = "刀片购买相关API")
public class BladePurchaseController extends BaseController
{
    @Autowired
    private IBladePurchaseService bladePurchaseService;
    @Autowired
    private IBladeAmountService bladeAmountService;

    /**
     * 查询刀片购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:bladePurchase:list')")
    @GetMapping("/list")
    @ApiOperation("获取刀片购买表信息")
    @ApiImplicitParam(name = "bladePurchase",value = "刀片购买实体类",paramType = "body", dataType = "BladePurchase")
    public TableDataInfo list(BladePurchase bladePurchase)
    {
        startPage();
        List<BladePurchase> list = bladePurchaseService.selectBladePurchaseList(bladePurchase);
        return getDataTable(list);
    }

    /**
     * 导出刀片购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:bladePurchase:export')")
    @Log(title = "刀片购买信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出刀片购买表信息")
    @ApiImplicitParam(name = "bladePurchase",value = "刀片购买实体类",paramType = "body", dataType = "BladePurchase")
    public AjaxResult export(BladePurchase bladePurchase)
    {
        List<BladePurchase> list = bladePurchaseService.selectBladePurchaseList(bladePurchase);
        ExcelUtil<BladePurchase> util = new ExcelUtil<BladePurchase>(BladePurchase.class);
        return util.exportExcel(list, "刀片购买信息数据");
    }

    /**
     * 获取刀片购买信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:bladePurchase:query')")
    @GetMapping(value = "/{bladePurchaseId}")
    @ApiOperation("获取刀片购买表单个信息")
    @ApiImplicitParam(name = "bladePurchaseId",value = "刀片购买实体类主键",paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("bladePurchaseId") Long bladePurchaseId)
    {
        return AjaxResult.success(bladePurchaseService.selectBladePurchaseById(bladePurchaseId));
    }

    /**
     * 新增刀片购买信息并更新刀片量表
     */
    @PreAuthorize("@ss.hasPermi('production:bladePurchase:add')")
    @Log(title = "刀片购买信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增刀片购买表信息")
    @ApiImplicitParam(name = "bladePurchase",value = "刀片购买实体类",paramType = "body", dataType = "BladePurchase")
    public AjaxResult add(@RequestBody BladePurchase bladePurchase)
    {
        return toAjax(bladePurchaseService.insertPurchaseUpdateAmount(bladePurchase));
    }

    /**
     * 修改刀片购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:bladePurchase:edit')")
    @Log(title = "刀片购买信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改刀片购买表信息")
    @ApiImplicitParam(name = "bladePurchase",value = "刀片购买实体类",paramType = "body", dataType = "BladePurchase")
    public AjaxResult edit(@RequestBody BladePurchase bladePurchase)
    {
        return toAjax(bladePurchaseService.updateBladePurchase(bladePurchase));
    }

    /**
     * 删除刀片购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:bladePurchase:remove')")
    @Log(title = "刀片购买信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bladePurchaseIds}")
    @ApiOperation("删除刀片购买表信息")
    @ApiImplicitParam(name = "bladePurchaseIds",value = "刀片购买实体类主键",paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] bladePurchaseIds)
    {
        return toAjax(bladePurchaseService.deleteBladePurchaseByIds(bladePurchaseIds));
    }
}
